package com.codedef.user.controller;

import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.stp.StpUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

/**
 * @author 孙宏宇
 * @date 2021/3/11 09:22
 */
@Slf4j
@RestController
public class UserConroller {

    @RequestMapping(path = "/login", method = {RequestMethod.GET, RequestMethod.POST})
    public String login(String username, String password) {
        log.info(username + ' ' + password);
        StpUtil.setLoginId(9527);
        return "LOGIN_SUCCESS";
    }

    @SaCheckLogin
    @GetMapping("check")
    public String check() {
        return "Welcome " + StpUtil.getLoginIdAsInt();
    }

    @GetMapping("/logout")
    public String logout() {
        StpUtil.logout();
        return "LOGOUT_SUCCESS";
    }

}
